package baseitems 
{
	import flash.automation.StageCapture;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.text.TextFieldAutoSize;
	import property.Align;
	import fl.text.TLFTextField;

	/**
	 * Текстовое поле
	 * @author artem.kolesnikov 
	 */
	public class LabelTextField extends Item 
	{
		private var textField:TLFTextField;
		public function LabelTextField(id:int, type:String) 
		{
			super(id, type);
			textField = new TLFTextField();
			
			var textSting:String = "I´m trying to vertical align some text in a Monoline TextField in AS3. Not sure if this can be done with TextFormat, but I don´t think so.";
			textField.text = textSting;// подставлять сюда цитаты кастанеды
			textField.autoSize = TextFieldAutoSize.NONE;
			textField.width = width;
			textField.height = height;
			textField.wordWrap = true;
			textField.mouseEnabled = false;
			textField.selectable = false;
			container.addChild(textField);
			
			textField.mouseChildren = false
			textField.verticalAlign = "middle";
		}
		

		// при центровке по высоте делаем ширину = контейнеру а высоту по тексту. наоборот-наоборот
		override public function set selected(value:Boolean):void {
			super.selected = value;
		}
		
		override public function refresh():void {
			textField.width = width;
			textField.height = height;
			super.refresh();
			var tf:TextFormat = new TextFormat();
			tf.size = this.textFieldSize;
			textField.setTextFormat(tf);
			setTextAlign();
		}
		
		private function setTextAlign():void {
			const TOP:String = "top";
			const CENTER:String = "middle";
			const BOTTOM:String = "bottom";
			var tf:TextFormat = new TextFormat();
			if (labelAlign == Align.TOP_LEFT) {
				textField.verticalAlign = TOP;
				tf.align = TextFormatAlign.LEFT;
			}
			
			if (labelAlign == Align.MIDDLE_LEFT) {
				textField.verticalAlign = CENTER;
				tf.align = TextFormatAlign.LEFT;
			}
			
			if (labelAlign == Align.BOTTOM_LEFT) {
				textField.verticalAlign = BOTTOM;
				tf.align = TextFormatAlign.LEFT;
			}
			
			if (labelAlign == Align.MIDDLE_TOP) {
				textField.verticalAlign = TOP;
				tf.align = TextFormatAlign.CENTER;
			}
			
			if (labelAlign == Align.MIDDLE) {
				textField.verticalAlign = CENTER;
				tf.align = TextFormatAlign.CENTER;
			}
			
			if (labelAlign == Align.MIDDLE_BOTTOM) {
				textField.verticalAlign = BOTTOM;
				tf.align = TextFormatAlign.CENTER;
			}
			
			if (labelAlign == Align.TOP_RIGHT) {
				textField.verticalAlign = TOP;
				tf.align = TextFormatAlign.RIGHT;
			}
			
			if (labelAlign == Align.MIDDLE_RIGHT) {
				textField.verticalAlign = CENTER;
				tf.align = TextFormatAlign.RIGHT;
			}
			
			if (labelAlign == Align.BOTTOM_RIGHT) {
				textField.verticalAlign = BOTTOM;
				tf.align = TextFormatAlign.RIGHT;
			}
			
			textField.setTextFormat(tf);
		}
	}
}